package manager;

import entity.Class;
import entity.TeacherClassDetails;
import iface.IManager;
import java.util.ArrayList;

/**
 *
 * @author Noi
 */
public class TeacherClassDetailsManager implements IManager<TeacherClassDetails> {

    private ArrayList<TeacherClassDetails> teacherClassDetailsList;

    public TeacherClassDetailsManager() {
        this.teacherClassDetailsList = new ArrayList<TeacherClassDetails>();
    }

    @Override
    public boolean add(TeacherClassDetails teacherClassDetails) {
        return this.teacherClassDetailsList.add(teacherClassDetails);
    }

    @Override
    public boolean remove(TeacherClassDetails teacherClassDetails) {
        return this.teacherClassDetailsList.remove(teacherClassDetails);
    }

    @Override
    public TeacherClassDetails replace(int index, TeacherClassDetails teacherClassDetails) {
        for (int i = 0; i < this.teacherClassDetailsList.size(); i++) {
            if (this.teacherClassDetailsList.get(i).getTeacherClassDetailsID() == teacherClassDetails.getTeacherClassDetailsID()) {
                this.teacherClassDetailsList.get(i).setTeacherID(teacherClassDetails.getTeacherID());
            }
            return this.teacherClassDetailsList.get(i);
        }
        return null;
    }

    @Override
    public int size() {
        return this.teacherClassDetailsList.size();
    }

    @Override
    public TeacherClassDetails get(int index) {
        return this.teacherClassDetailsList.get(index);
    }

    @Override
    public TeacherClassDetails getById(int id) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public TeacherClassDetails getByClassID(String id) {
        for (TeacherClassDetails obj : this.teacherClassDetailsList) {
            if (obj.getClassID().equals(id)) {
                return obj;
            }
        }
        return null;
    }

    @Override
    public TeacherClassDetails getByName(String name) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setVisible(TeacherClassDetails obj, boolean value) {
        for (TeacherClassDetails object : this.teacherClassDetailsList) {
            if (obj.getTeacherClassDetailsID() == object.getTeacherClassDetailsID()) {
                object.setStatus(value);
            }
            break;
        }
    }

    public TeacherClassDetails contains(TeacherClassDetails details) {
        for (TeacherClassDetails object : this.teacherClassDetailsList) {
            if (details.getTeacherID() == object.getTeacherID() && details.getClassID().equals(object.getClassID())) {
                return object;
            }
            break;
        }
        return null;
    }

    public ArrayList<TeacherClassDetails> getByTeacherID(int teacherID) {
        ArrayList<TeacherClassDetails> alClass = new ArrayList<TeacherClassDetails>();
        for (TeacherClassDetails details : this.teacherClassDetailsList) {
            if(details.getTeacherID() == teacherID) {
                alClass.add(details);
            }
        }
        return alClass;
    }
}
